const cottonFields = [
  '播种-出苗天数', '出苗-现蕾天数', '现蕾-开花天数', '开花-吐絮天数', '整个生育期天数',
  '整体株型', '果枝长短', '果枝夹角', '茎秆粗细', '红茎比例',
  '叶片是否含绒毛', '叶片大小', '叶片厚度',
  '单位面积有效株数', '单位面积有效铃数', '单位面积籽棉产量', '单位面积皮棉产量',
  '纤维长度', '断裂比强度', '马克隆值', '整齐度', '断裂伸长率',
  '苗期病害调查', '立枯病', '生长期病害调查', '枯萎病', '铃期病害调查', '黄萎病', '红腐病', '虫害调查', '棉蚜', '蓟马', '红蜘蛛', '棉铃虫'
];

Page({
  data: {
    rows: 0,
    cols: 0,
    matrix: [],
    cottonFields,
    otherInfo: ''
  },
  onLoad(options) {
    const rows = Number(options.rows);
    const cols = Number(options.cols);
    let matrix = wx.getStorageSync('matrix') || [];
    let otherInfo = wx.getStorageSync('otherInfo') || '';
    if (!matrix.length || matrix.length !== rows || matrix[0].length !== cols) {
      matrix = [];
      for (let i = 0; i < rows; i++) {
        const row = [];
        for (let j = 0; j < cols; j++) {
          row.push({ row: i, col: j, value: {} });
        }
        matrix.push(row);
      }
    }
    this.setData({ rows, cols, matrix, otherInfo });
  },
  editCell(e) {
    const { row, col } = e.currentTarget.dataset;
    const that = this;
    wx.navigateTo({
      url: `/pages/matrix/form?row=${row}&col=${col}`
    });
  },
  onOtherInfoInput(e) {
    this.setData({ otherInfo: e.detail.value });
  },
  saveData() {
    wx.setStorageSync('matrix', this.data.matrix);
    wx.setStorageSync('otherInfo', this.data.otherInfo);
    wx.showToast({ title: '已保存到本地', icon: 'success' });
  }
}); 